package com.chuangsi.common.enums;

import cn.hutool.core.util.StrUtil;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public enum OrderStatusEnum {

    audit(1, "待审核"),
    pass(2, "通过"),
    reject(3, "已驳回"),
    applySurrender(4, "申请退保"),
    alreadySurrender(5, "已退保"),
    rejectSurrender(6, "退保驳回"),
    stop(7, "中止"),
    cancel(8, "作废")
    ;


    /**
     * 状态code
     */
    private Integer status;
    /**
     * 状态名称
     */
    private String statusName;

    OrderStatusEnum(Integer status, String statusName) {
        this.status = status;
        this.statusName = statusName;
    }


    public static String getName(Object status) {
        if(status == null|| StrUtil.isBlank(status.toString())){
            return "";
        }
        Integer myStatus;
        try {
            myStatus = Integer.parseInt(status.toString());
        }catch (Exception exception){
            return "-";
        }

        for (OrderStatusEnum orderStatusEnum : values()) {
            if(orderStatusEnum.getStatus().equals(myStatus)) return orderStatusEnum.getStatusName();
        }
        return "";
    }

    public static boolean exist(Object status) {
        if(status == null|| StrUtil.isBlank(status.toString())){
            return false;
        }
        Integer myStatus;
        try {
            myStatus = Integer.parseInt(status.toString());
        }catch (Exception exception){
            return false;
        }
        List<Integer> statusList = Arrays.stream(values()).map(OrderStatusEnum::getStatus).collect(Collectors.toList());
        boolean flag = statusList.contains(myStatus);
        return flag;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getStatusName() {
        return statusName;
    }

    public void setStatusName(String statusName) {
        this.statusName = statusName;
    }
}
